// 引入路由，补充守卫
import router from './index'
import store from '../store/index'
const vipList = ['/setting', '/abc']
router.beforeEach(function (to, from, next) {
  console.log(to.path)
  // to要跳入的页面是viplist中的某一个
  if (vipList.includes(to.path)) {
    if (store.state.tokenInfo.token) {
      next()
    } else {
      next('/login?backto=' + encodeURIComponent(to.fullPath))
      // fullPath属性比起path属性多了查询字符串的参数
    }
  } else if (to.path === '/login') {
    if (store.state.tokenInfo.token) {
      console.log('您已经登录了，就不能去login，这边转到了 / ')
      next('/')
    } else {
      next()
    }
  } else {
    next()
  }
})
router.afterEach(function (to, from) {
  console.log('路由变化了,afterEach')
})
export default router
